﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Masters/WithoutPermBasic.Master" AutoEventWireup="true" CodeBehind="AssignAllPerm.aspx.cs" Inherits="PMS.UI.BD.AssignAllPerm" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
        $(function () {
            var rowData;
            var height = $("#divTotal").height();

            var content = parseFloat(height) - 30;
            $("#tbList").css("height", content);
        });
    </script>
    <script type="text/javascript">
        var Id = com.get.Id;
        var action = com.get.action;
        var type = com.get.type;
        $(function () {
            com.ajax({
                url: "/Logic/BD/RoleAjax.aspx?method=GetPermTree",
                data: { Id: Id, type: type },
                success: function (data) {
                    LoadTree(data);
                }
            });
        });


        function LoadTree(r) {
            //  console.log(r);
            //   var data = JSON.parse(r);
            //加载原始数据列表
            $("#tbList").treegrid({
                data: r,
                loadMsg: '数据加载中请稍后……',
                fitColumns: true,
                idField: "Id",
                treeField: "Name",
                singleSelect: false,
                checkOnSelect: false,
                striped: true,
                lines: true,
                columns: [[{
                    field: '', width: 30, formatter: function (value, row, Index) {
                        if (row.checked == true) {
                            return "<input type='checkbox' name='perm'  cbxId='" + row.Id + "' checked='checked'/>";
                        }
                        else {
                            return "<input cbxId='" + row.Id + "' name='perm' type='checkbox'/>";
                        }
                    }
                },
                 {
                     field: 'Name', title: '权限名称', align: "left"
                 }, {
                     field: "Id", title: '按钮', formatter: function (value, row, Index) {

                         var btnData = row.btn;
                         if (btnData == null) {
                             return "";
                         }
                         else {
                             var result = "";

                             for (var i = 0; i < btnData.length; i++) {
                                 //  console.log(btnData[i]);
                                 if (btnData[i].checked == true) {
                                     result += "<input type='checkbox' name='btnPerm'   cbxId='" + btnData[i].Id + "' checked='checked'/>" + btnData[i].Name;
                                 }
                                 else {
                                     result += "<input name='btnPerm' cbxId='" + btnData[i].Id + "' type='checkbox'/>" + btnData[i].Name;
                                 }
                             }
                             return result;
                         }
                     }
                 }, {
                     field: 'btn', title: '操作', width: 60, align: "center", formatter: function (value, row, Index) {

                         return "<input type='button' value='全选' name='btnCheckAll' /><input type='button' name=btnUnCheckAll value='全不选' />"
                     }
                 }
                ]],
                onLoadSuccess: function () {

                    $("#tbList").treegrid("collapseAll");
                    $("input[name=btnCheckAll]").click(function () {
                        $(this).closest("tr").find("input:checkbox").not("input:checked").prop("checked", true);

                    });

                    $("input[name=btnUnCheckAll]").click(function () {

                        $(this).closest("tr").find("input:checked").prop("checked", false);
                    });


                },

            });
        }
    </script>
    <script type="text/javascript">

        function Save() {
            var permIds = "";
            var btnPermIds = "";
            $("#divTotal").find("input[name=perm]:checked").each(function () {
                permIds += $(this).attr("cbxId") + ",";
            });

            $("#divTotal").find("input[name=btnPerm]:checked").each(function () {
                btnPermIds += $(this).attr("cbxId") + ",";
            });

            com.ajax({
                url: "/Logic/BD/RoleAjax.aspx?method=EditRolePermTree",
                data: { permIds: permIds, btnPermIds: btnPermIds, type: type, Id: Id },
                success: function (data) {
                    com.message(data.state, data.msg);
                    top.wrapper.tabCurrentClose();
                }
            });
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceToorbar" runat="server">
    <a href="javascript:void(0)" id="Save" class="easyui-linkbutton" onclick="Save()"
        data-options="iconCls:'icon-save',plain:true">保存</a> &nbsp;&nbsp;

</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
    <div id="divTotal" style="height: 100%; width: 100%">
        <table id="tbList" title="权限列表" style="width: 100%">
        </table>
    </div>
</asp:Content>
